<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            故障提报
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">设备编码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描设备编码" id="equipCode" value="" onclick="getIdSelector();" />
                        </select>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">故障等级</div>
                    <div class="aui-list-item-input">
                        <select id="faultLevel">
                    </select>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">故障类别</div>
                    <div class="aui-list-item-input">
                        <select id="faultClass">
                    </select>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label ui-selectee">故障描述</div>
                    <div class="aui-list-item-input ui-selectee"> <input class="form-control" type="text" id="description">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 45%;">故障提报时间</div>
                    <div class="aui-list-item-input">
                        <input readonly class="form-control" type="text" id="faultdate" placeholder="请选择">
                    </div>
                </div>
            </li>
            <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 45%;">维修开始时间</div>
                    <div class="aui-list-item-input">
                        <input readonly class="form-control" type="text" id="beginDate" placeholder="请选择">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 45%;">维修结束时间</div>
                    <div class="aui-list-item-input">
                        <input readonly class="form-control" type="text" id="endDate" placeholder="请选择">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 45%;">实际工时(分)</div>
                    <div class="aui-list-item-input">
                        <input class="form-control" type="text" id="actualtime">
                    </div>
                </div>
            </li> -->
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">班组</div>
                    <div class="aui-list-item-input">
                        <select id="teamGid">
                    </select>
                    </div>
                </div>
            </li>
            <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 45%;">横向展开</div>
                    <div class="aui-list-item-input">
                        <input class="form-control" type="text" id="horizontalExpansion">
                    </div>
                </div>
            </li> -->
            <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 45%;">维修描述</div>
                    <div class="aui-list-item-input">
                        <input class="form-control" type="text" id="repairDescription">
                    </div>
                </div>
            </li> -->
            <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 45%;">原因分析</div>
                    <div class="aui-list-item-input">
                        <input class="form-control" type="text" id="causeAnalysis">
                    </div>
                </div>
            </li> -->
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 45%;">再发防止对策</div>
                    <div class="aui-list-item-input">
                        <input class="form-control" type="text" id="recurrencePrevention">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width: 45%;">备注</div>
                    <div class="aui-list-item-input">
                        <input class="form-control" type="text" id="remark">
                    </div>
                </div>
            </li>
            <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">状态</div>
                    <div class="aui-list-item-input">
                        <select id="status">
                    </select>
                    </div>
                </div>
            </li> -->

        </ul>
        <p></p>
        <p></p>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">保存</div>

    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jdate.min.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var equipCode = ""; //设备编码
    var faultLevel = ""; //故障等级
    var faultClass = ""; //故障类别
    var description = ""; //故障描述
    var faultdate = ""; //故障提报时间
    //var status = ""; //状态
    var teamGid = ""; //班组
    // var beginDate = ""; //维修开始时间
    // var endDate = ""; //维修结束时间
    // var actualtime = ""; //实际工时(分)
    //var horizontalExpansion = ""; //横向展开
    //var repairDescription = ""; //维修描述
    // var causeAnalysis = ""; //原因分析
    var recurrencePrevention = ""; //再发防止对策
    var remark = ""; //备注


    //初始化查询仓库下拉框
    apiready = function() {

        $("#equipCode").focus();
        idSelector = "equipCode";

        //查询故障等级下拉框
        doSearchMdparaconfig("emEquipmentFaultLevel", "faultLevel");
        //查询故障类别下拉框
        doSearchMdparaconfig("emEquipmentFaultClass", "faultClass");
        //查询状态下拉框
        doSearchMdparaconfig("emEquipmentFaultStatus", "status");
        //查询班组下拉框
        doSearchTeamGid();


        new Jdate({
            el: '#faultdate',
            format: 'YYYY-MM-DD hh:mm:ss',
            beginYear: 2000,
            endYear: 2100
        });
        // new Jdate({
        //     el: '#beginDate',
        //     format: 'YYYY-MM-DD hh:mm:ss',
        //     beginYear: 2000,
        //     endYear: 2100
        // });
        // new Jdate({
        //     el: '#endDate',
        //     format: 'YYYY-MM-DD hh:mm:ss',
        //     beginYear: 2000,
        //     endYear: 2100
        // })
    }


    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function(ret, err) {
            //alert(ret);扫码的结果都是编码
            //1：设备编码
            if (idSelector == 'equipCode') {

                $("#equipCode").val(ret);
                //查询仓库
                //getWorkCenter(ret, idSelector);
            }
        });
    }

    //业务参数下拉框
    function doSearchMdparaconfig(paracls, idH) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getMdparaconfig";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                paracls: paracls,
                un:un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId(idH), html);
            }
        });
    }
    //班组下拉框
    function doSearchTeamGid() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                tablename: "md_labour_group",
                column_name: "group_name",
                column_value: "sysid",
                condition: " is_delete=0 ",
                un : un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                }
                $api.html($api.byId("teamGid"), html);
            }
        });
    }

    //保存按钮
    function save() {
        //设备编码
        var equipCode = $("#equipCode").val();
        //故障等级
        var faultLevel = $("#faultLevel").val();
        //故障类别
        var faultClass = $("#faultClass").val();
        //故障描述
        var description = $("#description").val();
        //故障提报时间
        var faultdate = $("#faultdate").val();
        //班组
        var teamGid = $("#teamGid").val();
        //箱再发防止对策
        var recurrencePrevention = $("#recurrencePrevention").val();
        //备注
        var recurrencePrevention = $("#remark").val();

        //设备非空校验
        if (equipCode == "" || equipCode == null || equipCode == undefined) {
            api.toast({
                msg: '请选择/扫描设备',
                duration: 3000
            });
            return;
        }

        //故障等级非空校验
        if (faultLevel == "" || faultLevel == null || faultLevel == undefined) {
            api.toast({
                msg: '请选择故障等级',
                duration: 3000
            });
            return;
        }

        //故障类别非空校验
        if (faultClass == "" || faultClass == null || faultClass == undefined) {
            api.toast({
                msg: '请选择故障类别',
                duration: 3000
            });
            return;
        }



        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un'); //登录用户
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/emequipmentfaultAdd";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                equipCode: equipCode, //设备编码
                faultLevel: faultLevel, // 故障等级
                faultClass: faultClass, //故障类别
                description: description, //故障描述
                faultdate: faultdate, //故障提报时间
                teamGid: teamGid, //班组
                recurrencePrevention: recurrencePrevention, //再发防止对策
                remark: remark, //备注
                status: "0", //状态为 未完成
                ext01: "1", //app状态-1-已提报
                un: un //登录用户
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            console.log(ret);
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                    api.openWin({
                        name: "emequipmentfaultList",
                        url: "emequipmentfaultList" + '.html',
                    });

                } else if (myobj.code == '1') {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }



    //扫描之后条码解析
    function tmSplit(sm) {
        var arr = sm.split(",");
        // if (arr.length == 10) {
        $("#tm").val(sm);
        if (arr[1] == null || arr[1] == undefined) {
            $("#mrlCode").val("");
        } else {
            $("#mrlCode").val(arr[1]);
        }
        if (arr[2] == null || arr[2] == undefined) {
            $("#qty").val("");
        } else {
            $("#qty").val(arr[2]);
        }
        if (arr[3] == null || arr[3] == undefined) {
            $("#lotCode").val("");
        } else {
            $("#lotCode").val(arr[3]);
        }
        if (arr[9] == null || arr[9] == undefined) {
            $("#boxnum").val("");
        } else {
            $("#boxnum").val(arr[9]);
        }
        // } else {
        //     api.toast({
        //         msg: '该条码不符合条码规则',
        //         duration: 3000
        //     });
        //     return;
        // }
        //自动入库
        saveAuto();
    }

    //箱号监听回车事件
    $("#boxnum").on('keypress', function(e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {

            $("#boxnum").select();
            //调用条码解析+保存事件
            tmSplit(tm);
        }
    });

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
